package gui_layer;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;

@SuppressWarnings("serial")
public abstract class SaleRestockManageWindow extends UniversalTableWindow
{
	/**
	 * Create the frame.
	 */
	public SaleRestockManageWindow()
	{
		super();
		make_option_buttons();
		set_table_params();
	}

	private void make_option_buttons()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		JButton btnNew = new JButton("New");
		btnNew.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnNew.setForeground(Color.WHITE);
		btnNew.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnNew.setContentAreaFilled(false);
		btnNew.setOpaque(true);
		btnNew.setBorder(new RoundedCornerBorder());
		btnNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { create_new(); }});
		option_button_panel.add(btnNew);
		
		JButton btnDetails = new JButton("Details");
		btnDetails.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnDetails.setForeground(Color.WHITE);
		btnDetails.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnDetails.setContentAreaFilled(false);
		btnDetails.setOpaque(true);
		btnDetails.setBorder(new RoundedCornerBorder());
		btnDetails.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { details(); }});
		option_button_panel.add(btnDetails);
		
		JButton btnDelete = new JButton("Delete");
		btnDelete.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnDelete.setForeground(Color.WHITE);
		btnDelete.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnDelete.setContentAreaFilled(false);
		btnDelete.setOpaque(true);
		btnDelete.setBorder(new RoundedCornerBorder());
		btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { delete(); }});
		option_button_panel.add(btnDelete);
	}
	
	private void set_table_params()
	{
		
		table.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				if (e.getClickCount() == 2)
				{
					details();
				}
			}
		});
		
		table.addKeyListener(new KeyAdapter()
		{
			public void keyTyped(KeyEvent e)
			{
				if (e.getKeyChar() == '\u007F')
				{
					delete();
				}
			}
		});
	}
	
	protected abstract void create_new();
	
	protected abstract void details();
	
	protected abstract void delete();

}
